package com.youbu.demo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Random;

/**
 * 生成随机文件
 * @author sunfangwei
 **/
public class RanDemo {


	public static void main(String[] args)
	{



		try
		{
			File file = new File("D:\\jf4.txt");
			if(!file.exists())
			{	//如果不存在data.txt文件则创建
				file.createNewFile();
				System.out.println("jf.txt创建完成");
			}
			//创建文件写入
			FileWriter fw = new FileWriter(file,true);
			BufferedWriter bw = new BufferedWriter(fw);
			//产生随机数据，写入文件
			Random random = new Random();
			for(long i=0;i<100000000L;i++)
			{
				int randint = -5+(int)(Math.random()*(10-(-5)+1));;
				int userId =(int)Math.floor((random.nextDouble()*100.0));
				bw.write(userId+","+randint);
				//新的一行
				bw.newLine();
			}
			bw.close();
			fw.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}


}
